#pragma once
#include <winsock.h>
#include <stdio.h>

#define PORT       5150

#define MSGSIZE    1024



#pragma comment(lib, "ws2_32.lib")

enum ServerStatus
{
    UnStart = 0,
    Idle,
    link,
    End,
    UnKnow
};

class SocketServerMgr:base::Thread
{
public:

public:
    class Listener
    {
    public:
        virtual void SSM_OnStartCreateServerBegin()=0;
        virtual void SSM_OnStartCreateServerEnd(const bool is_succ, const std::string& msg, const int type) = 0;

        virtual void SSM_OnDisconncet() = 0;

        virtual void SSM_OnGetMssage(const char* msg) = 0;
        virtual void SSM_OnAcceptClient(bool is_link) = 0;

        virtual void SSM_OnSendMssageBegin() = 0;
        virtual void SSM_OnSendMssageEnd(const bool is_succ, const int type) = 0;

        virtual void SSM_OnStatuChange(const int statu) = 0;
    };

    SocketServerMgr(Listener* p);
    ~SocketServerMgr();

    void OnCreateServer();
    void OnSendMssage(const char* msg);
    void OnStartGetMssage();
    void OnDiconnect();
    void OnStopServer();
    void AcceptFun();
private:
    void StatuChange(ServerStatus statu);
private:
    Listener* listener_ = nullptr;

    base::Thread accept_thread_;
    ServerStatus statu_ = UnKnow;
};

